package br.com.news.web;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;

import br.com.news.web.service.AcessoNoticiaService;
import br.com.news.web.service.CadastroService;
import br.com.news.web.service.CategoriaService;
import br.com.news.web.service.CategoriaUsuarioService;
import br.com.news.web.service.EnqueteService;
import br.com.news.web.service.FonteService;
import br.com.news.web.service.NoticiaService;
import br.com.news.web.service.UsuarioService;

public class BaseMB implements Serializable{
	
	private static final NoticiaService noticia;
	private static final CadastroService cadastroService;
	private static final CategoriaService categoriaService;
	private static final AcessoNoticiaService acessoNoticiaService;
	private static final CategoriaUsuarioService categoriaUsuarioService;
	private static final UsuarioService usuarioService;
	private static final FonteService fonteService;
	private static final EnqueteService enqueteService;
	
	static {
		noticia = new NoticiaService();
		cadastroService = new CadastroService();
		categoriaService = new CategoriaService();
		acessoNoticiaService = new AcessoNoticiaService();
		categoriaUsuarioService = new CategoriaUsuarioService();
		usuarioService = new UsuarioService();
		enqueteService = new EnqueteService();
		fonteService = new FonteService();
	}

	private static final long serialVersionUID = 3865703446494440173L;

	protected void addErrorMessage(String componentId, String errorMessage){
		addMessage(componentId, errorMessage,FacesMessage.SEVERITY_ERROR);
	}
	
	protected void addErrorMessage(String errorMessage){
		addErrorMessage(null, errorMessage);
	}
	
	protected void addInfoMessage(String componentId, String infoMessage){
		addMessage( componentId, infoMessage, FacesMessage.SEVERITY_INFO);
	}

	protected void addInfoMessage(String infoMessage){
		addInfoMessage(null, infoMessage);
	}
	
	private void addMessage(String componentId, String errorMessage, Severity severity){
		FacesMessage message = new FacesMessage(errorMessage);
		message.setSeverity(severity);
		FacesContext.getCurrentInstance().addMessage(componentId, message);
	}

	public static NoticiaService getNoticia() {
		return noticia;
	}

	public static CadastroService getCadastroService() {
		return cadastroService;
	}

	public static CategoriaService getCategoriaService() {
		return categoriaService;
	}

	public static AcessoNoticiaService getAcessoNoticiaservice() {
		return acessoNoticiaService;
	}

	public static CategoriaUsuarioService getCategoriaUsuarioservice() {
		return categoriaUsuarioService;
	}

	public static UsuarioService getUsuarioservice() {
		return usuarioService;
	}

	public static EnqueteService getEnqueteService() {
		return enqueteService;
	}
	
	public static FonteService getFonteservice() {
		return fonteService;
	}

	public String getValueParameter(String nameParameter) {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		return (String) facesContext.getExternalContext().
        getRequestParameterMap().get(nameParameter);
		
		
	}
	
}
